<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .gray{
            color: gray;
        }
        .black{
            color: black;
        }
    </style>
</head>
<body>
    <input type="text" class="gray" value="请输入搜索关键字" id="text"><br>
    <input type="submit" id="submit">
    <script>
        // 获取元素
        var text = document.getElementById("text");
            text.onfocus = function(){
                if(this.value == "请输入搜索关键字"){
                    this.value = "";
                    this.className = "black";
                }
            }
            text.onblur = function(){
                if(this.value == "" || this.value == "请输入搜索关键字"){
                    this.value = "请输入搜索关键字";
                    this.className = "gray";
                }
            }

    </script>
</body>
</html>